package business;

import gui.MyNoteAppGUI;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class MyNoteAppSave
{

    private String title;
    private String date;
    private String note;
    private File openNote;

    public MyNoteAppSave(String title, String date, String note)
    {
        this.title = title;
        this.date = date;
        this.note = note;
        saveNote();
    }

    private String createSaveTitle(String title)
    {
        String saveTitle = "";

        saveTitle = title + "//";
        return saveTitle;
    }

    private String createSaveDate(String date)
    {
        String saveDate = "";

        saveDate = date + "//";
        return saveDate;
    }

    private String createSaveNote(String note)
    {
        String saveNote = "";

        saveNote = note + "//";
        return saveNote;
    }

    private void saveNote()
    {

        try
        {
            String filename;
            filename = title + "-" + date + ".txt";
            File noteFile = new File(filename);
            FileWriter saveNote = new FileWriter(noteFile);
            BufferedWriter writeSaveNote = new BufferedWriter(saveNote);

            title = createSaveTitle(title);
            date = createSaveDate(date);
            note = createSaveNote(note);

            writeSaveNote.write(title);
            writeSaveNote.newLine();
            writeSaveNote.write(date);
            writeSaveNote.newLine();
            writeSaveNote.write(note);

            writeSaveNote.flush();
            writeSaveNote.close();

        } catch (IOException e)
        {
            System.out.println("IO-Exception:" + e.getMessage());
        } catch (Exception e)
        {
            System.out.println("Fehler:" + e.getMessage());
        }

    }

   
}
